package com.contract.spirit.ui.password

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.contract.commonlib.http.status.ResultState
import com.contract.commonlib.base.BaseViewModel
import com.contract.commonlib.http.ext.request
import com.contract.spirit.config.SmsCodeConfig
import com.contract.spirit.func.net.rxApi
import com.contract.spirit.manage.CommonConfigManager

/**
 * @author: witness
 * created: 2021/9/28
 * desc:
 */
class PasswordViewModel : BaseViewModel() {
    var smsCodeValue = ObservableField<String>()
    var password = ObservableField<String>()
    var password2 = ObservableField<String>()

    val setPasswordRes = MutableLiveData<ResultState<String>>()
    val emsCodeObservel = MutableLiveData<ResultState<String>>()


    fun getSmsCode() {
        request(
            {
                rxApi.getEmsCode(
                    CommonConfigManager.userInfoResponse.phone!!,
                    SmsCodeConfig.SETPAYPWD
                )
            },
            emsCodeObservel,
            isShowDialog = true,
            loadingMessage = true
        )
    }

    fun setPassword() {
        request(
            { rxApi.setPassword(password.get().toString(), smsCodeValue.get().toString()) },
            setPasswordRes, isShowDialog = true, loadingMessage = true
        )
    }
}